<template>
  <div class="ad_content1">
    <div class="title_h1">基本资料</div>
    <div class="hang_msg" v-for="(item,index) in myInfo" :key="index">
      <div class="left_title">{{item.title}}</div>
      <el-input class="right_input" v-model="formDa[item.model]" :placeholder="item.place" size="small"></el-input>
    </div>
    <div class="hang_msg logo_img_llc" v-if="typeType != 2">
      <div class="left_title">LOGO图 : </div>
      <el-upload
        :action="http+'/api/common/fileupload'"
        list-type="picture-card"
        :on-preview="handlePictureCardPreview"
        :on-remove="handleRemove"
        :on-success="fileChange"
        :file-list="fileList"
        :limit="1"
      >
        <i class="el-icon-plus"></i>
      </el-upload>
      <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="" />
      </el-dialog>
    </div>
    <el-button @click="subData" type="warning" class="sub_btn">提交</el-button>
  </div>
</template>

<script>
import { Message } from 'element-ui';
export default {
  components: {

  },
  data() {
    return {
      http:"",
      formDa:{
        val1:"",
        val2:"",
        val3:"",
        val4:"",
        val5:"",
        val6:"",
        val7:"",
        val8:"",
        val9:"",
        val10:""
      },
      myInfo:[
        {title:"所在地区 : ",place:"请输入所在地区",model:"val1"},
        {title:"公司名称 : ",place:"请输入公司名称",model:"val2"},
        {title:"法定代表人 : ",place:"请输入法定代表人",model:"val3"},
        {title:"法人企业代码 : ",place:"请输入法人企业代码",model:"val4"},
        {title:"联系人 : ",place:"请输入联系人",model:"val5"},
        {title:"联系电话 : ",place:"请输入联系电话",model:"val6"},
        {title:"联系地址 : ",place:"请输入联系地址",model:"val7"},
        {title:"邮政编码 : ",place:"请输入邮政编码",model:"val8"},
        {title:"传真号码 : ",place:"请输入传真号码",model:"val9"},
        {title:"单位网址 : ",place:"请输入单位网址",model:"val10"},
      ],
      fileList: [],
      dialogImageUrl:"",
      dialogVisible: false,
      firstImg:"",
      typeType:1,
      routeQuery:{}
    };
  },
  beforeMount(){
    console.log(this.$route.query)
    this.routeQuery = this.$route.query
    this.typeType = Number(this.$route.query.type)
    this.http = this.$apiUrl;
    if(this.typeType == 2){
      this.myInfo = [
        {title:"所在地区 : ",place:"请输入所在地区",model:"val1"},
        {title:"真实姓名 : ",place:"请输入公司名称",model:"val2"},
        {title:"昵称 : ",place:"请输入法定代表人",model:"val3"},
        {title:"身份证号码 : ",place:"请输入法人企业代码",model:"val4"},
        // {title:"联系人 : ",place:"请输入联系人",model:"val5"},
        {title:"联系电话 : ",place:"请输入联系电话",model:"val6"},
        {title:"联系地址 : ",place:"请输入联系地址",model:"val7"},
        {title:"邮政编码 : ",place:"请输入邮政编码",model:"val8"},
        // {title:"传真号码 : ",place:"请输入传真号码",model:"val9"},
        {title:"个人主页 : ",place:"请输入单位网址",model:"val10"},
      ]
    }else{
      this.myInfo = [
        {title:"所在地区 : ",place:"请输入所在地区",model:"val1"},
        {title:"公司名称 : ",place:"请输入公司名称",model:"val2"},
        {title:"法定代表人 : ",place:"请输入法定代表人",model:"val3"},
        {title:"法人企业代码 : ",place:"请输入法人企业代码",model:"val4"},
        {title:"联系人 : ",place:"请输入联系人",model:"val5"},
        {title:"联系电话 : ",place:"请输入联系电话",model:"val6"},
        {title:"联系地址 : ",place:"请输入联系地址",model:"val7"},
        {title:"邮政编码 : ",place:"请输入邮政编码",model:"val8"},
        {title:"传真号码 : ",place:"请输入传真号码",model:"val9"},
        {title:"单位网址 : ",place:"请输入单位网址",model:"val10"},
      ]
    }
    if(this.$route.query.uid){
      let rouQuery = this.$route.query;
      this.$store.commit("login",{token:rouQuery.uid,type:rouQuery.type})
      this.initData({token:rouQuery.uid,type:rouQuery.type})
    }else{
      this.initData({})
    }
    
    

  },
  methods: {
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    fileChange(response, file, fileList) {
      console.log(response, file, fileList);
      this.firstImg = response.data;
    },
    initData(dataL){
      this.http = this.$apiUrl;
      if(this.typeType == 2 ){
        //基本资料
        this.$getApi("/common/gerenjbzl", { type: 2,token:this.routeQuery.uid ,id:this.routeQuery.cid}).then(
          (res) => {
            console.log(res.data, "基本资料");
            let dataC = res.data;
            if(dataC){
              this.formDa.val1 = dataC.city || ""
              this.formDa.val2 = dataC.name
              this.formDa.val3 = dataC.nickname
              this.formDa.val4 = dataC.idcard
              // this.formDa.val5 = dataC.phone
              this.formDa.val6 = dataC.phone
              this.formDa.val7 = dataC.address
              this.formDa.val8 = dataC.youzhengbm
              // this.formDa.val9 = dataC.chuanzhen
              this.formDa.val10 = dataC.url
              if(dataC.weblogo){
                this.fileList = [
                  { name: "ddd.jpeg", url: this.http + dataC.weblogo },
                ];
              }
            }
          }
        );
      }else{
      this.$getApi("/common/jibenziliao",dataL).then(res=>{
        console.log(res) 
        let dataC = res.data;
        if(dataC){
          this.formDa.val1 = dataC.city || ""
          this.formDa.val2 = dataC.webtitle
          this.formDa.val3 = dataC.faren
          this.formDa.val4 = dataC.companycode
          this.formDa.val5 = dataC.xianxianren
          this.formDa.val6 = dataC.webdianhua
          this.formDa.val7 = dataC.address
          this.formDa.val8 = dataC.youzbma
          this.formDa.val9 = dataC.chuanzhen
          this.formDa.val10 = dataC.gsurl
          if(dataC.weblogo){
            this.fileList = [
              { name: "ddd.jpeg", url: this.http + dataC.weblogo },
            ];
          }
        }
      })
      }
    },
    subData(){
      console.log(this.formDa)
      let dataL = {
        city:this.formDa.val1,
        webtitle:this.formDa.val2,
        faren:this.formDa.val3,
        companycode:this.formDa.val4,
        xianxianren:this.formDa.val5,
        webdianhua:this.formDa.val6,
        address:this.formDa.val7,
        youzbma:this.formDa.val8,
        chuanzhen:this.formDa.val9,
        gsurl:this.formDa.val10,
        weblogo:this.firstImg
      } ;
      this.$postApi("/common/jibenziliao",dataL).then(res=>{
        console.log(res) 
        // this.dataList = res.data; 
         Message({
          type: "success",
          message: "修改成功",
          showClose: true,
        });
      })
    }
  },
};
</script>
<style lang="stylus">
.logo_img_llc{
  .el-upload-list--picture-card .el-upload-list__item{
    width 240px
    height 70px
  }
  .el-upload--picture-card{
    width 240px
    height 70px
  }
  .el-upload-list__item-actions{
    width 240px
    height 70px
  }
  .el-upload--picture-card{
    line-height 100px
  }
}
</style>
<style scoped lang="stylus">
.ad_content1{
  background-color #fff
  padding-bottom 30px
  .sub_btn{
    display block
    width 300px;
    margin 30px 0 20px  200px
  }
  .title_h1{
    // text-align center;
    color #004173
    font-size 26px
    padding 20px 0 10px  60px 
    border-bottom 1px solid #f0f0f0
  }
  .hang_msg{
    display flex;
    align-items center
    padding 20px 0 10px 0
    font-size 16px
    .left_title{
      width 260px
      text-align right
      padding-right 8px
      color #004173
    }
    .right_input{
      width 360px  
    }
  }
}
</style>
